<template>
	<gracePage :isSwitchPage="true" :headerHeight="0">
		<view slot="gBody">	
			<!-- 轮播图 start -->
			<swiper class="grace-swiper"  autoplay="true" indicator-dots 
			indicator-color="rgba(255, 255, 255, 1)" indicator-active-color="#3688FF" 
			style="height:399rpx" interval="5000">
				<swiper-item class="grace-swiper-item" v-for="(item, index) in swiperItems" :key="index">
					<navigator url='' class="grace-img-in">
						<image :src="item" mode="widthFix" class="grace-swiper-image"></image>
					</navigator>
				</swiper-item>
			</swiper>
			<!-- 商品列表 -->		
			<!-- <view class="grace-grids grace-margin-top">
				<view v-for="(item, index) in objects" :key="index" @tap="detail(item)">
					<view class="grace-grids-items">
						<image class="grace-grids-icon-img" :src="item.field4" mode="widthFix"></image>
						<text class="grace-grids-text grace-h4 grace-bold grace-blue">{{item.field3}}</text>
					</view>
				</view>
			</view> -->
			
			<view class="grace-body">
				<view style="margin-top: 10%;">
					<view v-if="imei">
						<p class="grace-h3">设备名称：{{hardwareInfo.field5}}</p>
						<!-- <p class="grace-h3">物联网号：{{hardwareInfo.field2}}</p> -->
						<p class="grace-h3">网络状态：{{onLineState}}</p>
						<p class="grace-h3">设备电量：{{hardwareInfo.field8}}</p>
						<p class="grace-h3">监控状态：{{dataPushField6_3}}</p>
					</view>
				</view>
				<view class="grace-flex-center">
					<text v-if="!imei" class="grace-blue grace-h2" @tap="lend()">租借设备</text>
				</view>
			</view>
<!-- 			<view class="grace-body">
				<view class="grace-margin-top">
					<text class="grace-h2">实时湿度</text>
				</view>
				<view class="grace-flex-center">
					<text class="grace-blue grace-h2">85%</text>
				</view>
			</view> -->
			
			<!-- <view class="grace-body">
				<view class="grace-margin-top" style="margin-top: 50%;">
					<button form-type="submit" type="primary" class="grace-button">
						偷油告警演练
					</button>
				</view>
			</view> -->
			
			<!-- 按钮 -->
			<view class="grace-grids grace-margin-top grace-flex-center" style="margin-top: 20%;">
				<view class="grace-grids-items" @tap="buFang('on')">
					<image class="grace-grids-icon-img" src="/static/images/homeButtonImages/ICAO.png" mode="widthFix"></image>
					<text class="grace-grids-text grace-h3 grace-bold">布防</text>
				</view>
			
				<view class="grace-grids-items" @tap="buFang('off')">
					<image class="grace-grids-icon-img" src="/static/images/homeButtonImages/hangXian.png" mode="widthFix"></image>
					<text class="grace-grids-text grace-h3 grace-bold">撤防</text>
				</view>
				
				<view class="grace-grids-items" @tap="buFang('cancel')">
					<image class="grace-grids-icon-img" src="/static/images/homeButtonImages/caoZuo.png" mode="widthFix"></image>
					<text class="grace-grids-text grace-h3 grace-bold">消除</text>
				</view>
			</view>
			
			<!-- 升级下载进度 -->
			<!-- 遮罩组件 @closeShade="closeShade" 实现点击关闭自身，如果不需要次功能则不绑定此事件即可 -->
			<graceShade ref="graceShade">
				<view class="demo-msg grace-relative">
					<view class="demo-msg-in">
						<graceProgressButton :buttonText="buttonText" borderRadius="50rpx" :val="progress"></graceProgressButton>
					</view>
					<!-- <view class="close-btn grace-icons icon-close3 grace-white grace-absolute-rt"></view> -->
				</view>
			</graceShade>	
		</view>	
	</gracePage>
</template>
<script>
import graceHeader from '../../graceUI/components/graceHeader.vue';	
import gracePage from "../../graceUI/components/gracePage.vue";
import graceFlex from "../../graceUI/components/graceFlex.vue";
import graceProgressButton from "../../graceUI/components/graceProgressButton.vue";
import graceShade from "../../graceUI/components/graceShade.vue";
var _self; 
export default {
	data() {
		return {
			mainColor : '',
			appName : '',
			objects:[],
			address:"点此修改服务区域",
			loadMoreText : "加载更多",
			showLoadMore : false,
			pageNum : 1,
			//每次加载的记录数
			pageSize : 20,
			//解决列表触底加载过程中服务器新增数据问题
			createTimeTo : "",
			token:"",
			getTokenRetryNum:0,
			appInfo:"",
			userInfoData:"",
			wuLuCode : '',
			swiperItems : [],
			// 升级下载参数
			progress : 0,
			buttonText : "下载中,请稍后...",
			fileUrl  : '',
			imei:"",
			hardwareInfo:{
				createTime:"",
				field2:"",
				field3:"",
				field5:"",
				field7:"",
				field8:""
			},
			id:"",
			onLineState:"",
			dataPushField6_3:""
		}
	},
	onLoad: async function(e){
		_self = this;
		//获取主题颜色
		_self.mainColor = _self.$myFunction.appConfig().mainColor;
		//获取应用名称
		_self.appName = _self.$myFunction.appConfig().appName;
		//记录时间，用于列表查询，必须在查询列表请求前获取时间
		_self.createTimeTo = _self.$myFunction.nowTime('Y-m-d H:i:s');
		
		// _self.swiperItems = [
		// 	serverAddress+'common/img/wxAppPic/homeSwiperItems/home1.png',
		// 	serverAddress+'common/img/wxAppPic/homeSwiperItems/home2.png',
		// 	serverAddress+'common/img/wxAppPic/homeSwiperItems/home3.png'
		// ]
		_self.swiperItems = [
			// '../../static/images/homeSwiperItems/home1.jpg',
			// '../../static/images/homeSwiperItems/home2.jpg',
			'../../static/images/homeSwiperItems/home3.jpg'
		]

		/**
		 * 执行顺序：
		 * 第一步：获取token（先读取缓存、再获取）
		 * 第二步：获取应用信息（名称、描述、服务区域）（先读取缓存、再获取）
		 * 第三步：获取商品
		 * 
		 * 一、二、三请求服务器时（从服务器获取token）提示“请稍后”，请求失败或获取到需求时清除提示
		 */
		//获取token，同步方法
		_self.token =  await _self.$myFunction.getToken();
		_self.token = _self.token.token;
		if(!_self.$myFunction.isEmpty(_self.token)){
			_self.getList();
		}else{
			//再试一次
			_self.token =  await _self.$myFunction.getToken();
			_self.token = _self.token.token;
			_self.getList();
		}
		// 升级检测
		// // #ifdef APP-PLUS  
		// _self.firewareDownload();
		// // #endif  
		
	},
	onShow:function(e){
		_self.userInfoData = _self.$myFunction.appStorage('wuLuUserInfo');
		if(_self.userInfoData){
			_self.readWuLuCode();
		}
	},	
	onShareAppMessage(res) {
		return {
		  title: _self.appInfo.field5+" "+_self.appName,
		  path: '/pages/object/index?wuLuCode='+_self.wuLuCode
		}				
	},
	//分享到朋友圈
	//只支持Android版本
	onShareTimeline(){
		return {
			title: _self.appInfo.field5+" "+_self.appName,
			query: 'wuLuCode='+_self.wuLuCode
		}				
	},
	//页面滑动到底部
	onReachBottom() {
		_self.loadMoreText = "加载中...";
		_self.showLoadMore = true;
		_self.pageNum ++ ;
		_self.$myFunction.displayLog("pageNum:"+_self.pageNum);
		_self.getList();	
	},
	//下拉刷新
	onPullDownRefresh() {
		//重置相关参数开始
		_self.pageNum = 1;
		_self.loadMoreText = "加载更多";
		_self.showLoadMore = false;
		_self.createTimeTo = _self.$myFunction.nowTime('Y-m-d H:i:s');
		//重置相关参数结束
		_self.getList();
	},
	methods:{
		//第二步：获取应用信息（名称、描述、服务区域）（先读取缓存、再获取）
		getAppInfo: function(){
			if(!_self.$myFunction.appStorage('wuLuAppInfo')){
				_self.$myFunction.displayLog("没有从缓存中获取到应用信息，请求服务器获取应用信息");
				//从服务器获取应用信息
				_self.getAppInfoFromServer();
			}else{
				_self.$myFunction.displayLog("从缓存中获取到应用信息");
				_self.appInfo = _self.$myFunction.appStorage('wuLuAppInfo');
				// _self.address = "  "+_self.appInfo.field3.split(" ")[3];
				_self.wuLuCode = _self.appInfo.field1;
				_self.$myFunction.displayLog("wuLuCode:"+_self.wuLuCode);
			}
		},
		//第二步：获取应用信息——从服务器获取
		getAppInfoFromServer: function(){
			uni.showToast({
				title: '请稍后...',
				duration:_self.$myFunction.appConfig().requestWaitTime,
				icon: 'none',
			});
			var params = {
					'field1':_self.wuLuCode
				};
			//重新获取一次token，防止接口返回认证失败系统重新获取的token未被使用
			_self.token = _self.$myFunction.appStorage('wuLuToken').token;
			uni.request({
				url:  _self.$myFunction.appConfig().serverAddress+'hardwareList',
				data: params,
				method : "POST",
				header : {
					'content-type':'application/x-www-form-urlencoded',
					'Authentication':_self.token
				},		
				success: data => {
					uni.hideToast();
					_self.$myFunction.displayLog("getAppInfoFromServer服务器返回数据："+JSON.stringify(data));					
					if (data.data.code == 200) {
						if(data.data.data.total > 0){
							//缓存应用数据
							uni.setStorage({
								key: 'wuLuAppInfo',
								data: data.data.data.rows[0],
								success: function () {	
									_self.$myFunction.displayLog("缓存应用信息成功："+JSON.stringify(data.data.data.rows[0]));
									_self.appInfo = data.data.data.rows[0];
									// _self.address = "  "+_self.appInfo.field3.split(" ")[3];
								}
							});
						}else{
							_self.$myFunction.displayLog("从服务器获取应用信息失败");
						}						
					}else{
						//如果请求数据因token认证失败，则清空缓存token
						if(data.data.message.indexOf("接口访问未认证") != -1){
							uni.setStorage({
								key: 'wuLuToken',
								data: "",
								success: function () {	
									_self.$myFunction.displayLog("清空缓存token");
									//触发重新获取token
									_self.$myFunction.getToken();
									// 关闭所有页面，打开到应用内的某个页面。
									_self.$myFunction.displayLog("重加载当前页面");
									uni.reLaunch({
										url: '/pages/object/index'
									});
								}
							});
						}else{
							uni.showToast({title: '连接失败...',icon: 'none'});
						}
					}
				},
				fail: (data, code) => {
					uni.hideToast();
					uni.showToast({title: '连接失败...',icon: 'none'});
				}
			});
		},
		//第三步：获取列表
		getList: function(){
			_self.getProductionList();
		},
		// firewareDownload:function(){
		// 	let osType;
		// 	if (plus.os.name=="iOS") {  
		// 	    osType = "苹果";
		// 	}else{  
		// 	    osType = "安卓";
		// 	}
		// 	var params = {
		// 		'field3':osType,
		// 		'pageNum':1,
		// 		'pageSize':10,
		// 		'field':"createTime",
		// 		'order':'desc',
		// 		'status':"1"
		// 	};
		// 	uni.request({
		// 		url:  _self.$myFunction.appConfig().serverAddress+'huanJingKongZhiFirewareList',
		// 		data: params, 
		// 		method : "POST",
		// 		header : {
		// 			'content-type':'application/x-www-form-urlencoded',
		// 			'Authentication':_self.token
		// 		},	
		// 		success: (data) => {  
		// 			_self.$myFunction.displayLog("服务器返回数据："+JSON.stringify(data));
		// 			if (data.data.code == 200) {
		// 				let version = data.data.data.rows[0].field1;	
		// 				// _self.$myFunction.displayLog("服务器固件版本号："+version);
		// 				// 服务器版本号与App版本号比较
		// 				if(_self.$myFunction.version_compare(version,_self.$myFunction.appConfig().version)>0){
		// 					uni.showModal({ //提醒用户更新
		// 						title: "更新提示",  
		// 						content: data.data.data.rows[0].field2,  
		// 						success: (res) => {  
		// 							if (res.confirm) {  
		// 								// 弹出下载进度遮罩框
		// 								_self.$refs.graceShade.showIt();
		// 								let firewareDownloadUrl = _self.$myFunction.appConfig().serverIp+'download/huanJingKongZhiFirewareAnnexDownload?id='+data.data.data.rows[0].id;
		// 								_self.$myFunction.displayLog("固件下载地址："+firewareDownloadUrl);
		// 								//调用浏览器下载
		// 								// plus.runtime.openURL(firewareDownloadUrl);  
		// 								const downloadTask = uni.downloadFile({
		// 									url: firewareDownloadUrl, 
		// 									success: (res) => {
		// 										if (res.statusCode === 200) {
		// 											// 关闭下载进度遮罩框
		// 											_self.$refs.graceShade.hideIt();
		// 											_self.$myFunction.displayLog("下载成功");
		// 											uni.showToast({
		// 												title:'安装包下载成功，即将安装',
		// 												icon:'success'
		// 											})
		// 											plus.runtime.install(res.tempFilePath)
		// 										}
		// 									}
		// 								});
										
		// 								downloadTask.onProgressUpdate((res) => {
		// 									// console.log('下载进度' + res.progress);
		// 									// console.log('已经下载的数据长度' + res.totalBytesWritten);
		// 									// console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
		// 									_self.progress = res.progress;
		// 									// 满足测试条件，取消下载任务。
		// 									// if (res.progress > 50) {
		// 									// 	downloadTask.abort();
		// 									// }
		// 								});
		// 							}else if (res.cancel) {
		// 								console.log('用户点击取消');
		// 							}  
		// 						}  
		// 					}) 
		// 				}  
		// 			}else{
		// 				//如果请求数据因token认证失败，则清空缓存token
		// 				if(data.data.message.indexOf("接口访问未认证") != -1){
		// 					uni.setStorage({
		// 						key: 'wuLuToken',
		// 						data: "",
		// 						success: function () {	
		// 							_self.$myFunction.displayLog("清空缓存token");
		// 							//触发重新获取token
		// 							_self.$myFunction.getToken();
		// 							// 关闭所有页面，打开到应用内的某个页面。
		// 							_self.$myFunction.displayLog("重加载当前页面");
		// 							uni.reLaunch({
		// 								url: '/pages/object/index'
		// 							});
		// 						}
		// 					});
		// 				}else{
		// 					uni.showToast({title: "发生错误，请重试",icon: 'none'});
		// 				}	
		// 			}
		// 		},
		// 		fail: (data, code) => {
		// 			uni.showToast({title: '连接失败...',icon: 'none'});
		// 		}
		// 	}) 
		// },
		// 根据编码获取硬件信息
		 readHardwareIMEI:function(){
			 var params = {
				"field1":_self.wuLuCode
			 };
			 _self.$myFunction.displayLog("field1:"+_self.wuLuCode);
			 //重新获取一次token，防止接口返回认证失败系统重新获取的token未被使用
			 _self.token = _self.$myFunction.appStorage('wuLuToken').token;
			 uni.request({
				url:  _self.$myFunction.appConfig().serverAddress+'hardwareList',
				data: params, 
				method : "POST",
				header : {
					'content-type':'application/x-www-form-urlencoded',
					'Authentication':_self.token
				},	
				success: data => {
					// 刷新完毕后关闭刷新
					uni.hideToast();
					// 刷新完毕后关闭刷新
					uni.stopPullDownRefresh();
					_self.$myFunction.displayLog("readHardwareIMEI服务器返回数据："+JSON.stringify(data));
					if (data.data.code == 200) {
						if(data.data.data.rows.length > 0){
							_self.hardwareInfo = data.data.data.rows[0];	
							//在线状态判断
							//分钟数计算
							if(!_self.$myFunction.isEmpty(_self.hardwareInfo.field7)){
								var startDateTemp = _self.hardwareInfo.field7.replace(/-/g,'/')   //为了兼容IOS，需先将字符串转换为'2018/9/11 9:11:23'
								var startDate = Date.parse(startDateTemp);
								_self.$myFunction.displayLog("startDate:"+startDate);
								var endDateTemp = _self.$myFunction.nowTime("Y-m-d H:i:s").replace(/-/g,'/')   //为了兼容IOS，需先将字符串转换为'2018/9/11 9:11:23'
								var endDate = Date.parse(endDateTemp);
								_self.$myFunction.displayLog("endDate:"+endDate);
								var munites=parseInt((endDate - startDate)/(60*1000));
								_self.$myFunction.displayLog("munites:"+munites);
								if(munites > 10){
									_self.onLineState = "设备离线"
								}else{
									_self.onLineState = "设备在线"
								}
							}
							//field2——物联网号
							_self.imei = _self.hardwareInfo.field2;
							// 缓存数据
							uni.setStorage({
								key: 'imei',
								data: _self.imei,
								success: function() {
									_self.$myFunction.displayLog("imei缓存成功");
									// uni.$emit('createOrderAddressSelect', {
									// 	msg: '页面刷新'
									// });
								}
							});	
							_self.readLatestDatapushData();
						}else{
							// my_alert(".my_alert","设备未接入网络",true,"warning");
							uni.showToast({title: '设备未接入网络',icon: 'none'});
						}
					}else{
						//如果请求数据因token认证失败，则清空缓存token
						if(data.data.message.indexOf("接口访问未认证") != -1){
							uni.setStorage({
								key: 'wuLuToken',
								data: "",
								success: function () {	
									_self.$myFunction.displayLog("清空缓存token");
									//触发重新获取token
									_self.$myFunction.getToken();
									// 关闭所有页面，打开到应用内的某个页面。
									_self.$myFunction.displayLog("重加载当前页面");
									uni.reLaunch({
										url: '/pages/object/index'
									});
								}
							});
						}	
					}					
				},
				fail: (data, code) => {
					uni.hideToast();
					// 刷新完毕后关闭刷新
					uni.stopPullDownRefresh();
					uni.showToast({title: '连接失败...',icon: 'none'});
				}
			 })
		},
		// 根据物联网编码获取最新推送数据
		 readLatestDatapushData:function(){
			 var params = {
				"field1":_self.imei
			 };
			 //重新获取一次token，防止接口返回认证失败系统重新获取的token未被使用
			 _self.token = _self.$myFunction.appStorage('wuLuToken').token;
			 uni.request({
				url:  _self.$myFunction.appConfig().serverAddress+'dataPushList',
				data: params, 
				method : "POST",
				header : {
					'content-type':'application/x-www-form-urlencoded',
					'Authentication':_self.token
				},	
				success: data => {
					// 刷新完毕后关闭刷新
					uni.hideToast();
					// 刷新完毕后关闭刷新
					uni.stopPullDownRefresh();
					_self.$myFunction.displayLog("readLatestDatapushData服务器返回数据："+JSON.stringify(data));
					if (data.data.code == 200) {
						if(data.data.data.rows.length > 0){
							let dataPushField6 = data.data.data.rows[0].field6.split(",");
							if(dataPushField6[3][2] == "1"){
								_self.dataPushField6_3 = "防控中"
							}else{
								_self.dataPushField6_3 = "已撤防"
							}
						}else{
							// my_alert(".my_alert","设备未接入网络",true,"warning");
							uni.showToast({title: '设备未推送数据',icon: 'none'});
						}
					}else{
						//如果请求数据因token认证失败，则清空缓存token
						if(data.data.message.indexOf("接口访问未认证") != -1){
							uni.setStorage({
								key: 'wuLuToken',
								data: "",
								success: function () {	
									_self.$myFunction.displayLog("清空缓存token");
									//触发重新获取token
									_self.$myFunction.getToken();
									// 关闭所有页面，打开到应用内的某个页面。
									_self.$myFunction.displayLog("重加载当前页面");
									uni.reLaunch({
										url: '/pages/object/index'
									});
								}
							});
						}	
					}					
				},
				fail: (data, code) => {
					uni.hideToast();
					// 刷新完毕后关闭刷新
					uni.stopPullDownRefresh();
					uni.showToast({title: '连接失败...',icon: 'none'});
				}
			 })
		},
		buFang:function(temp){
			_self.userInfoData = _self.$myFunction.appStorage('wuLuUserInfo');
			if(!_self.userInfoData){
				//因此页面是主页面，页面显示完成之后才能进行是否登录判断，延时2秒解决未登录提示一闪而过现象
				uni.showToast({title: '您未登录',icon: 'none'});//默认显示1500毫秒
				setTimeout(function () {
					uni.navigateTo({
						url:"../public/login"
					})	
				}, 1500);
			}else{
				_self.wuLuCode = _self.$myFunction.appStorage('wuLuCode');
				if( _self.$myFunction.isEmpty(_self.wuLuCode)){
					uni.showToast({title: '无设备',icon: 'none'});//默认显示1500毫秒
					setTimeout(function () {
						uni.navigateTo({
							url:"../hardware/bind"
						})	
					}, 1500);
				}else{
					if(temp.indexOf("on") != -1){
						_self.remoteControl("1","1111");//震动开
					}else if(temp.indexOf("off") != -1){
						_self.remoteControl("0","1111");//震动关
					}else if(temp.indexOf("cancel") != -1){
						_self.remoteControl("0","1131");//测试
					}
				}
			}
		},
		/**
		 * 远程控制
		 * @param
		 */
		remoteControl:function(val,codeValue){
			_self.imei = _self.$myFunction.appStorage('imei');
			if( _self.$myFunction.isEmpty(_self.imei)){
				uni.showToast({title: '无设备',icon: 'none'});//默认显示1500毫秒
				setTimeout(function () {
					uni.navigateTo({
						url:"../hardware/bind"
					})	
				}, 1500);
			}else{
				var params = {
					"imei":_self.imei,
					"val":val,
					"oneNetCode":codeValue
				};
				//重新获取一次token，防止接口返回认证失败系统重新获取的token未被使用
				_self.token = _self.$myFunction.appStorage('wuLuToken').token;
				uni.showToast({
					title: '请稍后',
					duration: 50000,
					icon: 'loading'
				});
				_self.buttonFunctionState = 1;
				uni.request({
					url:  _self.$myFunction.appConfig().serverAddress+'downloadCode',
					data: params, 
					method : "POST",
					header : {
						'content-type':'application/x-www-form-urlencoded',
						'Authentication':_self.token
					},	
					success: function (data) {
						uni.hideToast();
						_self.$myFunction.displayLog("remoteControl服务器返回数据："+JSON.stringify(data));
						//{"code":200,"data":"success"}
						//{"code":500,"message":"下发失败"}
						if (data.data.code === 200) {
							if(codeValue == "1111"){
								if(val == "1"){
									_self.dataPushField6_3 = "防控中"
								}else if(val == "0"){
									_self.dataPushField6_3 = "已撤防"
								}
							}
							// my_alert(".my_alert","操作成功！",false,"success");
							uni.showToast({title: '操作成功！',icon: 'success'});
						}else{
							// my_alert(".my_alert","下发失败",false,"warning");
							uni.showToast({title: '下发失败',icon: 'none'});
						}
						_self.buttonFunctionState=0;
					},
					complete:function (data) {
						_self.buttonFunctionState=0;
					},
					error:function (data) {
						uni.showToast({title: '请重试',icon: 'none'});
						_self.buttonFunctionState=0;
						// console.log(JSON.stringify(data));
						// {"readyState":4,"responseText":"{\"message\":\"接口访问未认证，请先进行认证\"}","responseJSON":{"message":"接口访问未认证，请先进行认证"},"status":401,"statusText":"error"}
						if(JSON.stringify(data).indexOf("接口访问未认证") != -1){
							uni.setStorage({
								key: 'wuLuToken',
								data: "",
								success: function () {	
									_self.$myFunction.displayLog("清空缓存token");
									//触发重新获取token
									_self.$myFunction.getToken();
									// 关闭所有页面，打开到应用内的某个页面。
									_self.$myFunction.displayLog("重加载当前页面");
									uni.reLaunch({
										url: '/pages/hardware/index'
									});
								}
							});
						}
					},
					fail: (data, code) => {
						uni.hideToast();
						uni.showToast({title: '连接失败...',icon: 'none'});
					}
				})
			}
		},
		detail:function(item){
			_self.userInfoData = _self.$myFunction.appStorage('wuLuUserInfo');
			if(!_self.userInfoData){
				uni.showToast({title: '您未登录',icon: 'none'});//默认显示1500毫秒
				setTimeout(function () {
					uni.navigateTo({
						url:"../loginReg/index"
					})	
				}, 1500);
			}else{
				uni.navigateTo({
					url:"../production/detail?id="+item.id
				})
			}			
		},
		// 第三步：获取列表
		getProductionList: function(){
			uni.showToast({
				title: '请稍后...',
				duration:_self.$myFunction.appConfig().requestWaitTime,
				icon: 'none',
			});
			var params = {
				'field1':'',
				'field2':'油箱卫士',
				'field3':'',
				'field4':'',
				'field5':'',
				'field6':'',
				'field7':'',
				'field8':'',
				'field9':'',
				'field10':'',
				'field11':'',
				'field12':'',
				'field13':'',
				'field14':'',
				'field15':'',
				'field16':'',
				'field17':'',
				'field18':'',
				'field19':'',
				'field20':'',
				'field21':'',
				'field22':'',
				'field23':'',
				'field24':'',
				'status':"1",
				'createTimeFrom':'',
				'createTimeTo':_self.createTimeTo,
				'pageNum':_self.pageNum,
				'pageSize':_self.pageSize,
				'order':'asc',
				'field':"createTime"
			};
			var paramsData = {
				"jsonParas":_self.$AesUtil.encrypt(encodeURIComponent(JSON.stringify(params)))
			}
			//重新获取一次token，防止接口返回认证失败系统重新获取的token未被使用
			_self.token = _self.$myFunction.appStorage('wuLuToken').token;
			uni.request({
				url:  _self.$myFunction.appConfig().serverAddress+'productionList',
				data: paramsData,
				method : "POST",
				header : {
					'content-type':'application/x-www-form-urlencoded',
					'Authentication':_self.token
				},		
				success: data => {
					uni.hideToast();
					_self.$myFunction.displayLog("getProductionList服务器返回数据："+JSON.stringify(data));					
					if (data.data.code == 200) {
						//总记录数
						var total = data.data.data.total;
						_self.$myFunction.displayLog("服务器返回数据总记录数："+total);
						var objectsData=data.data.data.rows;
						_self.$myFunction.displayLog("服务器返回当前查询条件记录数："+objectsData.length);						
						if(total == 0){//查询到0条记录
							
						}else{
							_self.objects.splice(0);	
							for (let i = 0; i < objectsData.length; i++) {
								//图片路径处理
								objectsData[i].field4 = _self.$myFunction.appConfig().serverIp+"resource/youXiangWeiShi/productionImage/"+objectsData[i].field1+"/"+objectsData[i].field4;
								// console.log("tesr:"+objectsData[i].field4);
								_self.objects.push(objectsData[i]);
							}
							_self.id = objectsData[0].id;
						}
						//对于已登录用户，读取设备信息
						_self.userInfoData = _self.$myFunction.appStorage('wuLuUserInfo');
						if(_self.userInfoData){
							_self.readWuLuCode();
						}
					}else{
						//如果请求数据因token认证失败，则清空缓存token
						if(data.data.message.indexOf("接口访问未认证") != -1){
							uni.setStorage({
								key: 'wuLuToken',
								data: "",
								success: function () {	
									_self.$myFunction.displayLog("清空缓存token");
									//触发重新获取token
									_self.$myFunction.getToken();
									// 关闭所有页面，打开到应用内的某个页面。
									_self.$myFunction.displayLog("重加载当前页面");
									uni.reLaunch({
										url: '/pages/object/index'
									});
								}
							});
						}else{
							_self.$myFunction.displayLog("需求列表读取失败："+JSON.stringify(data));
							uni.showToast({title: '连接失败...',icon: 'none'});
						}	
					}				
				},
				fail: (data, code) => {
					uni.hideToast();
					uni.showToast({title: '连接失败...',icon: 'none'});
					// 刷新完毕后关闭刷新
					uni.stopPullDownRefresh();
				}
			});
		},
		lend:function(){
			_self.userInfoData = _self.$myFunction.appStorage('wuLuUserInfo');
			if(!_self.userInfoData){
				uni.showToast({title: '您未登录',icon: 'none'});//默认显示1500毫秒
				setTimeout(function () {
					uni.navigateTo({
						url:"../loginReg/index"
					})	
				}, 1500);
			}else{
				uni.navigateTo({
					url:"../production/detail?id="+_self.id
				})
			}			
		},
		// 根据用户手机号获取wuLuCode
		 readWuLuCode:function(){
			  _self.wuLuCode = _self.$myFunction.appStorage('wuLuCode');
			 if(!_self.$myFunction.isEmpty(_self.wuLuCode)){
			 	//设备信息
			 	_self.readHardwareIMEI();
			 }else{
				 var params = {
					'field1':'',
					"field2":_self.userInfoData.field2,
					'field3':'',
					'field4':'',
					'field5':'',
					'field6':'',
					'field7':'',
					'field8':'',
					'field9':'',
					'field10':'',
					'field11':'',
					'field12':'',
					'field13':'',
					'field14':'',
					'field15':'',
					'field16':'',
					'field17':'油箱卫士',
					'field18':'',
					'field19':'',
					'field20':'',
					'field21':'',
					'field22':'',
					'field23':'',
					'field24':'',
					'status':"1",
					'createTimeFrom':'',
					'createTimeTo':_self.createTimeTo,
					'pageNum':_self.pageNum,
					'pageSize':_self.pageSize,
					'order':'asc',
					'field':"createTime"
				 };
				 var paramsData = {
					"jsonParas":_self.$AesUtil.encrypt(encodeURIComponent(JSON.stringify(params)))
				 }
				 //重新获取一次token，防止接口返回认证失败系统重新获取的token未被使用
				 _self.token = _self.$myFunction.appStorage('wuLuToken').token;
				 uni.request({
					url:  _self.$myFunction.appConfig().serverAddress+'normalUserList',
					data: paramsData, 
					method : "POST",
					header : {
						'content-type':'application/x-www-form-urlencoded',
						'Authentication':_self.token
					},	
					success: data => {
						// 刷新完毕后关闭刷新
						uni.hideToast();
						// 刷新完毕后关闭刷新
						uni.stopPullDownRefresh();
						_self.$myFunction.displayLog("readWuLuCode服务器返回数据："+JSON.stringify(data));
						if (data.data.code == 200) {
							if(data.data.data.rows.length > 0){
								_self.wuLuCode = data.data.data.rows[0].field5;
								// 缓存数据
								uni.setStorage({
									key: 'wuLuCode',
									data: _self.wuLuCode,
									success: function() {
										_self.$myFunction.displayLog("wuLuCode缓存成功");
									}
								});	
								//设备信息
								_self.readHardwareIMEI();
							}else{
								uni.showToast({title: '无用户数据',icon: 'none'});
							}
						}else{
							//如果请求数据因token认证失败，则清空缓存token
							if(data.data.message.indexOf("接口访问未认证") != -1){
								uni.setStorage({
									key: 'wuLuToken',
									data: "",
									success: function () {	
										_self.$myFunction.displayLog("清空缓存token");
										//触发重新获取token
										_self.$myFunction.getToken();
										// 关闭所有页面，打开到应用内的某个页面。
										_self.$myFunction.displayLog("重加载当前页面");
										uni.reLaunch({
											url: '/pages/object/index'
										});
									}
								});
							}	
						}					
					},
					fail: (data, code) => {
						uni.hideToast();
						// 刷新完毕后关闭刷新
						uni.stopPullDownRefresh();
						uni.showToast({title: '连接失败...',icon: 'none'});
					}
				 })
			}		
		},
	},
	components:{
		graceHeader,
		gracePage,
		graceFlex,
		graceProgressButton,
		graceShade
	}
}
</script>
<style>
	@import "../../static/iconfont/iconfont.css";
	@import "../../graceUI/animate.css";
	/* 图标大小 */
	.grace-grids-items{width:250rpx;}
	.grace-grids-icon-img{width:150rpx; height:150rpx;}
	page{background-image:linear-gradient(to bottom,#255fb0,#f6f7f8); background-repeat:no-repeat; background-size:100% 500rpx; background-color:#F6F7F8;}
	/* 下载进度遮罩层 */
	.demo-msg{width:600rpx; font-size:0;}
	.demo-msg-in{width:600rpx; height:0rpx;}
</style>